package com.yangyouli.unity_demo_server.service.impl;

import java.util.List;

import com.yangyouli.unity_demo_server.annotation.Inject;
import com.yangyouli.unity_demo_server.annotation.Injectable;
import com.yangyouli.unity_demo_server.dao.FriendsDao;
import com.yangyouli.unity_demo_server.entity.Friends;
import com.yangyouli.unity_demo_server.entity.FriendsVO;
import com.yangyouli.unity_demo_server.service.FriendsService;
import com.yangyouli.unity_demo_server.util.Page;
import com.yangyouli.unity_demo_server.util.PageWithData;

@Injectable
public class FriendsServiceImpl implements FriendsService {

	@Inject
	private FriendsDao friendsDao;
	
	@Override
	public int addFriends(Friends friends) {
		// 先查找是否有该好友关系
		if (friendsDao.find(friends) == null) {
			return friendsDao.add(friends);
		}
		return -1;
	}

	@Override
	public int deleteFriends(Friends friends) {
		return friendsDao.delete(friends);
	}

	@Override
	public List<FriendsVO> findFriends(int userId) {
		return friendsDao.findFriends(userId);
	}

	@Override
	public PageWithData<String, FriendsVO> findUserByName(Page<String> page) {
		return friendsDao.findUserByName(page);
	}

	@Override
	public Friends find(Friends friend) {
		return friendsDao.find(friend);
	}

	@Override
	public FriendsVO findByUserId(int userId) {
		return friendsDao.findUserById(userId);
	}
}
